package com.zzptc.zzsgz.bdsjws.activities;

import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.fragments.FirstFraqment;
import com.zzptc.zzsgz.bdsjws.fragments.SecondFragment;

import butterknife.BindView;

public class OneKeySOSActivity extends BaseActivity {
    FirstFraqment firstFraqment;
    @BindView(R.id.toolbar_sos)
    Toolbar toolbarSos;
    @BindView(R.id.fl_sos)
    FrameLayout flSos;
    @BindView(R.id.img_question)
    ImageView imgQuestion;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int getContentXML() {
        return R.layout.activity_one_key_sos;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        setSupportActionBar(toolbarSos);
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);
        //加载fragment
        if (firstFraqment == null) {
            firstFraqment = new FirstFraqment();
        }                                                                             //回退
        getFragmentManager().beginTransaction().replace(R.id.fl_sos, firstFraqment).addToBackStack("sos").commit();

    }

    public void toSecondFragment() {
        getFragmentManager().beginTransaction().hide(firstFraqment).add(R.id.fl_sos, new SecondFragment()).addToBackStack("sos").commit();
        //让question图标消失    在回退时图标在显示出来
        imgQuestion.setVisibility(View.GONE);

    }

    @Override
    public void onBackPressed() {
//        super.onBackPressed();
        if (getFragmentManager().getBackStackEntryCount() > 1){
            getFragmentManager().popBackStack();
            imgQuestion.setVisibility(View.VISIBLE);
        }else {
            finish();
        }

    }
}
